<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" v-loading="state.loading" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
				<el-tabs v-model="state.activeName" @tab-click="handleClick" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
					<el-tab-pane label="基础信息" name="first">
						<!-- 付费会员 * 代金券 -->
						<jcxx :productTypeList="state.query.productTypeList" ref="jcxxRef" @stepChange="stepChange"></jcxx>
					</el-tab-pane>
					<el-tab-pane label="商品规格" name="second">
						<shipingg :skuAttrTypeList="state.query.skuAttrTypeList" ref="shipinggRef" @stepChange="stepChange"></shipingg>
					</el-tab-pane>
					<el-tab-pane label="商品详情" name="third">
						<spxq ref="spxqRef" @stepChange="stepChange"></spxq>
					</el-tab-pane>
					<el-tab-pane label="商品权限" name="fourth">
						<spqx ref="spqxRef" :restrictBuyList="state.query.restrictBuyList" 
							@stepChange="stepChange"></spqx>
					</el-tab-pane>
					<el-tab-pane label="营销设置" name="fifth">
						<yxsz ref="yxszRef" :membershipList="state.query.membershipList"
							:recommend="state.query.recommend"
							:paymembershipList="state.query.paymembershipList" @stepChange="stepChange">
						</yxsz>
					</el-tab-pane>
					<el-tab-pane label="会员折扣" name="sixth">
						<hyzk ref="hyzkRef" :membershipList="state.query.membershipList" 
							:paymembershipList="state.query.paymembershipList" @stepChange="stepChange">
						</hyzk>
					</el-tab-pane>
					<el-tab-pane label="佣金设置" name="seventh">
						<yjsz ref="yjszRef" :distributionCommissionTypeList="state.query.distributionCommissionTypeList" 
							@stepChange="stepChange" @submitFun="submitFun"></yjsz>
					</el-tab-pane>
					<el-tab-pane label="商品协议" name="eighth">
						<fwcn ref="fwcnRef" :distributionCommissionTypeList="state.query.distributionCommissionTypeList" 
							@stepChange="stepChange" @submitFun="submitFun"></fwcn>
					</el-tab-pane>
				</el-tabs>
			</el-card>
		</div>
	</div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, nextTick, defineAsyncComponent } from 'vue';
import { spuDetail, spuCreate } from "/@/api/commodity";
import { configData } from "/@/api/common";
import { ElMessageBox, ElMessage } from 'element-plus';
import { useRoute } from 'vue-router';
import { goodsInfo } from '/@/stores/goods';
const goodsInfoData = goodsInfo()
import router from '/@/router';
const route = useRoute();
const jcxx = defineAsyncComponent(() => import('/@/components/createGoods/jcxx.vue'))
const shipingg = defineAsyncComponent(() => import('/@/views/commodity/videoList/components/shipingg.vue'))
const spxq = defineAsyncComponent(() => import('/@/components/createGoods/spxq.vue'))
const spqx = defineAsyncComponent(() => import('/@/components/createGoods/spqx.vue'))
const yxsz = defineAsyncComponent(() => import('/@/components/createGoods/yxsz.vue'))
const hyzk = defineAsyncComponent(() => import('/@/components/createGoods/hyzk.vue'))
const yjsz = defineAsyncComponent(() => import('/@/components/createGoods/yjsz.vue'))
const fwcn = defineAsyncComponent(() => import('/@/components/createGoods/fwcn.vue'))


const jcxxRef = ref();
const shipinggRef = ref();
const spxqRef = ref();
const spqxRef = ref();
const yxszRef = ref();
const hyzkRef = ref();
const yjszRef = ref();
const fwcnRef = ref();
const state = reactive({
	loading: false,
	activeName: 'first' as String,
	queryData:{},
	query: {
		// 商品类型列表
		productTypeList: [] as Array<any>,
		// 商品类型spu规格项属性数据
		skuAttrTypeList: [] as Array<any>,
		// 商品推荐数据
		recommend: [] as Array<any>,
		// 限购分类列表
		restrictBuyList: [] as Array<any>,
		// 分销商等级列表 
		distributionCommissionTypeList: [] as Array<any>,
		// 会员等级列表
		membershipList: [] as Array<any>,
		// 付费会员等级列表
		paymembershipList: [] as Array<any>,
		// 商品spu规格列表
		spuSpecList : [] as Array<any>,
	},
});

const handleClick = () => {

}

// tab切换
const stepChange = (step: String) => {
	state.activeName = step
}

// 获取系统配置项
const getConfigDataFun = async () =>{
	let params = {
		dictType: ''// 数组传空默认全部
	}
	const { results } = await configData(params);
	nextTick(() => {
		state.queryData = results;
		state.query.productTypeList = state.queryData.spuType;
		state.query.recommend = state.queryData.recommend;
		state.query.membershipList = state.queryData.membershipLevel;
		state.query.paymembershipList = state.queryData.paidMembershipLevel;
		state.query.restrictBuyList = state.queryData.quotaType;
		state.query.distributionCommissionTypeList = state.queryData.commissionGroup;
		// 根据类型获取商品属性
		let attr : any =  state.query.productTypeList.find(item => item.dictValue == goodsInfoData.spuType);
		state.query.skuAttrTypeList = attr.children;
	})
}


// 商品新增 or 编辑提交
const submitFun = async () => {
	let params = {}
	console.log(goodsInfoData.storeService)
	const spuData = {
		// promulgateType:  //  商品发布类型
		// source:  //  商品来源
		isSingleSpec: goodsInfoData.isSingleSpec,
		tplId: goodsInfoData.tplId,
		spuId:goodsInfoData.spuId,  //商品spuId
		spuType: goodsInfoData.spuType,  // 商品spu类型
		spuName: goodsInfoData.spuName,
		title: goodsInfoData.title,
		subtitle: goodsInfoData.subTitle,
		sortNumber: goodsInfoData.sortNumber,
		spuTags:goodsInfoData.spuTags.name, // 商品标签文字
		spuColor:goodsInfoData.spuTags.color, // 商品标签颜色
		salesChannel: goodsInfoData.salesChannel,  // 销售渠道
		// salesStatus: goodsInfoData.salesStatus,  // 销售状态
		brandId: goodsInfoData.brandId, // 商品品牌ID
		imgUrl: goodsInfoData.imgUrl, //spu商品主图正方形
		imgOblongUrl: goodsInfoData.imgOblongUrl, //spu商品主图长方形
		imgScale: goodsInfoData.imgScale,// 商品图片视频比例
		imgOnline: goodsInfoData.imgOnline, // 商品轮播图数组
		isVideo: goodsInfoData.isVideo ? 1 : 0, // 是否添加视频
		videoUrl: goodsInfoData.videoUrl, // 视频链接
		videoAutoplay: goodsInfoData.videoAutoplay ? 1 : 0, //视频是否自动播放
		videoMuteplay: goodsInfoData.videoMuteplay ? 1 : 0, //视频是否静音播放
		storeTypes: goodsInfoData.storeTypes, //门店商品分类
		shopTypes: goodsInfoData.shopTypes, //商城商品分类
		note: goodsInfoData.note, //商品详情描述
		recommend: goodsInfoData.recommend, //商品推荐数组
		// 商品上架 selectID ,itemId上架类型 itemData上架时间
		productUp:{selectId:goodsInfoData.grounding,ruleList:[
			{itemId:goodsInfoData.grounding,itemDate:goodsInfoData.groundingTime}
		]},
		// 商品下架 selectID ,itemId下架类型 itemData下架时间
		productDown:{selectId:goodsInfoData.delisting,ruleList:[
			{itemId:goodsInfoData.delisting,itemDate:goodsInfoData.delistingTime}
		]},
		// coupon: goodsInfoData.coupon, //spu优惠券 营销
		transport: goodsInfoData.transport, //物流方式
		freightset: goodsInfoData.freightset, //运费设置
		freight: goodsInfoData.freightset == 1 ? goodsInfoData.freightNum : goodsInfoData.freightId , //运费固定价格或者运费模板ID
		salesOnlineChannel: goodsInfoData.salesOnlineChannel, //线上销售销售渠道
		storeSales:{
			selectId:goodsInfoData.storeSalesType,
			ruleList: goodsInfoData.storeSales.map(obj => ({itemId: obj.itemId}))   // 商品销售门店
		},
		storeService: {
			selectId:goodsInfoData.storeServiceType,
			ruleList: goodsInfoData.storeService.map(obj => ({itemId: obj.itemId})) // 商品服务门店
		},
		servicePromise:{}, //服务承诺
		browseAuthority: [{ // 浏览权限
			selectId: goodsInfoData.browseAuthority[0],
		}], 
		buyAuthority: [{ // 购买权限
			selectId: goodsInfoData.buyAuthority[0],
		}],
		quotaAuthority: {  // 商品限购数组
			selectId: goodsInfoData.quotaAuthority
		},
		memberIntegral: {  // 会员积分
			selectId: goodsInfoData.memberIntegral
		},
		paidmemberIntegral: {  // 付费会员积分
			selectId: goodsInfoData.paidmemberIntegral
		},
		deduMemberIntegral:{  // 会员积分抵扣类型
			selectId: goodsInfoData.memberIntegralDeduction
		},
		deduPaidmemberIntegral:{  // 付费会员积分抵扣类型
			selectId: goodsInfoData.paidmemberIntegralDeduction
		},
		memberBalance: {  //会员余额抵扣
			selectId: goodsInfoData.memberBalanceDeduction
		},
		paidmemberBalance: {  //付费会员余额抵扣
			selectId: goodsInfoData.paidmemberBalanceDeduction
		},
		memberDiscount: {  //会员折扣
			selectId: goodsInfoData.memberDiscount
		},
		paidmemberDiscount: {    //付费会员折扣
			selectId: goodsInfoData.paidmemberDiscount
		},
		commissionSet: {   //佣金设置
			selectId: goodsInfoData.commissionSet
		},
		specList: goodsInfoData.specList, //规格组合
		priceType : goodsInfoData.priceType,
		priceValue : goodsInfoData.priceValue,
		skuList:[] as Array<any> // 商品sku列表
	}
	// 商品浏览权限
	if( goodsInfoData.browseAuthority.includes(2) || goodsInfoData.browseAuthority.includes(4) || goodsInfoData.browseAuthority.includes(8)){
		let browseAuthority = [] as Array<any>
		if(goodsInfoData.browseAuthority.includes(2)){
			const item = {
				selectId: 2,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.borwseMember.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			browseAuthority.push(item)
		}
		if(goodsInfoData.browseAuthority.includes(4)){
			const item = {
				selectId: 4,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.borwsePaidMember.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			browseAuthority.push(item)
		}
		if(goodsInfoData.browseAuthority.includes(8)){
			const item = {
				selectId: 8,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.borwseLaber.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			browseAuthority.push(item)
		}
		spuData.browseAuthority = browseAuthority
	}
	// 商品购买权限
	if( goodsInfoData.buyAuthority.includes(2) || goodsInfoData.buyAuthority.includes(4) || goodsInfoData.buyAuthority.includes(8)){
		let buyAuthority = [] as Array<any>
		if(goodsInfoData.buyAuthority.includes(2)){
			const item = {
				selectId: 2,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.buyMember.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			buyAuthority.push(item)
		}
		if(goodsInfoData.buyAuthority.includes(4)){
			const item = {
				selectId: 4,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.buyPaidMember.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			buyAuthority.push(item)
		}
		if(goodsInfoData.buyAuthority.includes(8)){
			const item = {
				selectId: 8,
				ruleList: [] as Array<any>,
			}
			goodsInfoData.buyLaber.map((itemx)=>{
				item.ruleList.push({
					itemId: itemx.dictValue,
				})
			})
			buyAuthority.push(item)
		}
		spuData.buyAuthority = buyAuthority
	}
	// 服务承诺
	if(goodsInfoData.promiseList.length > 0){
		const item = {
			selectId: 0,
			ruleList: [] as Array<any>,
		}
		goodsInfoData.promiseList.map((itemx)=>{
			item.ruleList.push({
				itemId: itemx.promiseId,
			})
		})
		spuData.servicePromise = item
	}
	// 商品限购数据 单一限购;
	if( goodsInfoData.quotaAuthority == 2){
		spuData.quotaAuthority = {
			selectId: goodsInfoData.quotaAuthority,
			singleMinQuota: goodsInfoData.onceRestrictedPurchaseMinNum,
			singleMaxQuota:goodsInfoData.onceRestrictedPurchaseMaxNum,
			foreverQuota:goodsInfoData.longRestrictedPurchaseNumber,
		}
	}else if( goodsInfoData.quotaAuthority == 3){
		const mapAuthority = {
			selectId:goodsInfoData.quotaAuthority,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const authorityList = [] as Array<any>;
			state.query.restrictBuyList.map((itemx)=>{
				authorityList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.restrictBuyData[`restrictBuyItem${itemx.dictValue}Type`],
					ruleValue: item.restrictBuyData[`restrictBuyItem${itemx.dictValue}`]
				})
			})
			mapAuthority.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: authorityList
			})
		})
		spuData.quotaAuthority = mapAuthority
	}
	// 会员积分获取数据
	if( goodsInfoData.memberIntegral == 2){
		const mapIntegral = {
			selectId:goodsInfoData.memberIntegral,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const memberIntegralList = [] as Array<any>;
			state.query.membershipList.map((itemx)=>{
				memberIntegralList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.memberIntegralData[`memberIntegralItem${itemx.dictValue}Type`],
					ruleValue: item.memberIntegralData[`memberIntegralItem${itemx.dictValue}`]
				})
			})
			mapIntegral.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: memberIntegralList
			})
		})
		spuData.paidmemberIntegral = mapIntegral
	}
	// 付费会员积分获取数据
	if( goodsInfoData.paidmemberIntegral == 2){
		const mapIntegral = {
			selectId:goodsInfoData.paidmemberIntegral,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const paidMemberIntegralList = [] as Array<any>;
			state.query.paymembershipList.map((itemx)=>{
				paidMemberIntegralList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.paidMemberIntegralData[`paidMemberIntegralItem${itemx.dictValue}Type`],
					ruleValue: item.paidMemberIntegralData[`paidMemberIntegralItem${itemx.dictValue}`]
				})
			})
			mapIntegral.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: paidMemberIntegralList
			})
		})
		spuData.memberIntegral = mapIntegral
	}
	// 会员积分抵扣数据
	if( goodsInfoData.memberIntegralDeduction == 2){
		const mapIntegral = {
			selectId:goodsInfoData.memberIntegralDeduction,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const memberIntegralDeductionList = [] as Array<any>;
			state.query.paymembershipList.map((itemx)=>{
				memberIntegralDeductionList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.memberIntegralDeductionData[`memberIntegralDeductionItem${itemx.dictValue}Type`],
					ruleValue: item.memberIntegralDeductionData[`memberIntegralDeductionItem${itemx.dictValue}`]
				})
			})
			mapIntegral.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: memberIntegralDeductionList
			})
		})
		spuData.deduMemberIntegral = mapIntegral
	}
	// 付费会员积分抵扣数据
	if( goodsInfoData.paidmemberIntegralDeduction == 2){ 
		const mapIntegral = {
			selectId:goodsInfoData.paidmemberIntegralDeduction,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const paidmemberIntegralDeductionList = [] as Array<any>;
			state.query.paymembershipList.map((itemx)=>{
				paidmemberIntegralDeductionList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.paidMemberIntegralDeductionData[`paidMemberIntegralDeductionItem${itemx.dictValue}Type`],
					ruleValue: item.paidMemberIntegralDeductionData[`paidMemberIntegralDeductionItem${itemx.dictValue}`]
				})
			})
			mapIntegral.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: paidmemberIntegralDeductionList
			})
		})
		spuData.deduPaidmemberIntegral = mapIntegral
	}

	// 会员余额抵扣
	if( goodsInfoData.memberBalanceDeduction == 2){
		const mapBalance = {
			selectId:goodsInfoData.memberBalanceDeduction,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const memberBalanceDeductionList = [] as Array<any>;
			state.query.membershipList.map((itemx)=>{
				memberBalanceDeductionList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.memberBalanceDeductionData[`memberBalanceDeductionItem${itemx.dictValue}Type`],
					ruleValue: item.memberBalanceDeductionData[`memberBalanceDeductionItem${itemx.dictValue}`]
				})
			})
			mapBalance.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: memberBalanceDeductionList
			})
		})
		spuData.memberBalance = mapBalance
	}
	
	// 付费会员余额抵扣
	if( goodsInfoData.paidmemberBalanceDeduction == 2){
		const mapBalance = {
			selectId:goodsInfoData.paidmemberBalanceDeduction,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const paidmemberBalanceDeductionList = [] as Array<any>;
			state.query.paymembershipList.map((itemx)=>{
				paidmemberBalanceDeductionList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.paidMemberBalanceDeductionData[`paidMemberBalanceDeductionItem${itemx.dictValue}Type`],
					ruleValue: item.paidMemberBalanceDeductionData[`paidMemberBalanceDeductionItem${itemx.dictValue}`]
				})
			})
			mapBalance.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: paidmemberBalanceDeductionList
			})
		})
		spuData.paidmemberBalance = mapBalance
	}


	// 会员折扣数据
	if( goodsInfoData.memberDiscount == 2){
		const mapDiscount = {
			selectId:goodsInfoData.memberDiscount,
			ruleList:[] as Array<any>,
		}
		goodsInfoData.skuList.map((item)=>{
			const memberDiscountList = [] as Array<any>;
			state.query.membershipList.map((itemx)=>{
				memberDiscountList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.memberDiscountData[`memberDiscountItem${itemx.dictValue}Type`],
					ruleValue: item.memberDiscountData[`memberDiscountItem${itemx.dictValue}`]
				})
			})
			mapDiscount.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: memberDiscountList
			})
		})
		spuData.memberDiscount = mapDiscount
	}
	// 付费会员折扣数据
	if( goodsInfoData.paidmemberDiscount == 2){
		const mapDiscount = {
			selectId:goodsInfoData.paidmemberDiscount,
			ruleList:[] as Array<any>
		}
		goodsInfoData.skuList.map((item)=>{
			const memberDiscountList = [] as Array<any>;
			state.query.paymembershipList.map((itemx)=>{
				memberDiscountList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.paidMemberDiscountData[`paidMemberDiscountItem${itemx.dictValue}Type`],
					ruleValue: item.paidMemberDiscountData[`paidMemberDiscountItem${itemx.dictValue}`]
				})
			})
			mapDiscount.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: memberDiscountList
			})
		})
		spuData.paidmemberDiscount = mapDiscount
	}
	// 佣金设置
	if( goodsInfoData.commissionSet == 2){
		const mapCommission = {
			selectId:goodsInfoData.commissionSet,
			ruleList:[] as Array<any>
		}
		goodsInfoData.skuList.map((item)=>{
			const commissionList = [] as Array<any>;
			state.query.distributionCommissionTypeList.map((itemx)=>{
				commissionList.push({
					shipLevel: itemx.dictValue,
					ruleType: item.commissionData[`commissionDataItem${itemx.dictValue}Type`],
					ruleValue: item.commissionData[`commissionDataItem${itemx.dictValue}`]
				})
			})
			mapCommission.ruleList.push({
				skuSpecList: item.skuSpecList,
				memberList: commissionList
			})
		})
		spuData.commissionSet = mapCommission
	}


	goodsInfoData.skuList.map((item:any)=>{
		let itemData = {                
			skuSpecList:item.skuSpecList, // 规格组合
			salesStatus: 1, // 销售状态 0 下架 1 上架
			skuImgUrl:item.skuImgUrl,  // sku图片
			skuType: item.skuType, // 商品属性
			retailPrice:item.retailPrice, // 零售价
			referencePrice:item.referencePrice, // 划线价
			lowPrice:item.lowPrice, // 最低价
			costPrice:item.costPrice, // 成本价
			unit:item.unit, // 商品单位
			stock:item.stock, // 库存
			warnStock:item.warnStock, // 预警库存
			offlineSales:item.offlineSales, // 线下销量
			merchantCode:item.merchantCode, // 商家编码
			barCode:item.barCode, // 条形码
			giveGoods:item.giveGoods, // sku关联商品
			usableTimes:item.usableTimes, // 可用次数
			usableDuration:item.usableDuration, // 可用时长
			usableDurationUnit:item.usableDurationUnit, // 可用时长单位
			servicesDuration:item.servicesDuration, // 服务时长
			servicesFee: item.servicesFee, // 手工费
			isServices: item.isServices ? 1 : 0, // 是否计算手工量
			isPerformance: item.isPerformance ? 1 : 0, // 是否计算消耗业绩
			commission: item.commission, // 消耗提成
			commissionUnit: item.commissionUnit, // 消耗提成方式
			isDebtSales: item.isDebtSales ? 1 : 0, // 是否欠款销售
			isDebtServices: item.isDebtServices ? 1 : 0, // 是否欠款服务
			refundDeadline: item.refundDeadline, // 退款时限
			isAftersalesService: item.isAftersalesService ? 1 : 0, // 是否支持售后
			cardValue: item.cardValue, // 储值卡金额(元)
			isGift: item.isGift ? 1 : 0, // 是否存在赠金
			giftValue: item.giftValue, // 赠送金额
			giftAccountType: item.giftAccountType, // 赠金到账类型
			useType: [] as Array<any>, // 使用类型 以及使用商品
			useDiscountType: [] as Array<any>, // 使用折扣类型 使用折扣商品
			giftUseType: [] as Array<any>, // 赠金使用类型
			giftUseDiscountType: [] as Array<any>,// 赠金使用折扣类型
			// birthdayRoll: item.birthdayRoll, // 生日券关联优惠券ID //数组 []
			// monthGiveRoll: item.monthGiveRoll, // 月赠送券关联优惠券 //数组 []
			material: item.material, // 音视频商品关联文件
		}
		if(goodsInfoData.spuType == 4){
			if(item.giftAccountType == 0){
				itemData.giftAccountType = {
					selectId:0
				}
			}else if(item.giftAccountType == 1){
				itemData.giftAccountType = {
					selectId:1,
					ruleList:item.giftAccountValueList
				}
			}
		}
		// 储值卡金额使用类型 useType
		if(item.cardPriceUseType.length > 0){
			const useType = [] as Array<any>
			// 0时不参与
			if(item.cardPriceUseType.includes(0)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				useType.push(itemx)
			}
			// 1时商品类型参与
			if(item.cardPriceUseType.includes(1)){
				let itemx = {
					selectId: 1,
					ruleList:[] as Array<any>
				}
				// 可用使用类型
				if(item.bindTypeUseList.length > 0){
					item.bindTypeUseList.map((itemy:any) =>{
						itemx.ruleList.push({ itemArray:itemy.typeIdList})
					})
				}
				useType.push(itemx)
			}
			// 2时商品Sku参与
			if(item.cardPriceUseType.includes(2)){
				let itemx = {
					selectId: 2,
					ruleList:[] as Array<any>
				}
				// 可用使用商品
				if(item.bindSkuUseList.length > 0){
					item.bindSkuUseList.map((itemy:any) =>{
						itemx.ruleList.push({ itemId:itemy.skuId})
					})
				}
				useType.push(itemx)
			}
			itemData.useType = useType;
		}
		// 储值卡金额可折扣类型
		if(item.cardPriceDiscountType.length > 0){
			const useDiscountType = [] as Array<any>
			if(item.cardPriceDiscountType.includes(0)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				useDiscountType.push(itemx)
			}
			if(item.cardPriceDiscountType.includes(1)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				useDiscountType.push(itemx)
			}
			if(item.cardPriceDiscountType.includes(2)){
				let itemx = {
					selectId: 1,
					ruleList:[] as Array<any>
				}
				// 可用折扣类型
				if(item.bindTypeDiscountList.length > 0){
					item.bindTypeDiscountList.map((itemy:any) =>{
						itemx.ruleList.push({ itemArray:itemy.typeIdList,itemNum:10})
					})
				}
				useDiscountType.push(itemx)
			}
			if(item.cardPriceDiscountType.includes(4)){
				let itemx = {
					selectId: 2,
					ruleList:[] as Array<any>
				}
				// 可用折扣商品
				if(item.bindSkuDiscountList.length > 0){
					item.bindSkuDiscountList.map((itemy:any) =>{
						itemx.ruleList.push({ itemId:itemy.skuId,itemNum:10})
					})
				}
				useDiscountType.push(itemx)
			}
			itemData.useDiscountType = useDiscountType;
		}
		// 储值卡赠送金额使用类型
		if(item.cardBonusPriceUseType.length > 0){
			const giftUseType = [] as Array<any>
			if(item.cardBonusPriceUseType.includes(0)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				giftUseType.push(itemx)
			}
			if(item.cardBonusPriceUseType.includes(1)){
				let itemx = {
					selectId: 1,
					ruleList:[] as Array<any>
				}
				// 可用使用类型
				if(item.bindTypeHandselUseList.length > 0){
					item.bindTypeHandselUseList.map((itemy:any) =>{
						itemx.ruleList.push({ itemArray:itemy.typeIdList})
					})
				}
				giftUseType.push(itemx)
			}
			if(item.cardBonusPriceUseType.includes(2)){
				let itemx = {
					selectId: 2,
					ruleList:[] as Array<any>
				}
				if(item.bindSkuHandselUseList.length > 0){
					item.bindSkuHandselUseList.map((itemy:any) =>{
						itemx.ruleList.push({ itemId:itemy.skuId})
					})
				}
				giftUseType.push(itemx)
			}
			itemData.giftUseType = giftUseType;
		}
		// 储值卡赠送金额可折扣类型
		if(item.cardBonusPriceDiscountType.length > 0){
			const giftUseDiscountType = [] as Array<any>
			if(item.cardBonusPriceDiscountType.includes(0)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				giftUseDiscountType.push(itemx)
			}
			if(item.cardBonusPriceDiscountType.includes(1)){
				let itemx = {
					selectId: 0,
					ruleList:[] as Array<any>
				}
				giftUseDiscountType.push(itemx)
			}
			if(item.cardBonusPriceDiscountType.includes(2)){
				let itemx = {
					selectId: 1,
					ruleList:[] as Array<any>
				}
				// 可用折扣类型
				if(item.bindTypeDiscountList.length > 0){
					item.bindTypeDiscountList.map((itemy:any) =>{
						itemx.ruleList.push({ itemArray:itemy.typeIdList,itemNum:10})
					})
				}
				giftUseDiscountType.push(itemx)
			}
			if(item.cardBonusPriceDiscountType.includes(4)){
				let itemx = {
					selectId: 2,
					ruleList:[] as Array<any>
				}
				// 赠金可用折扣商品
				if(item.bindSkuHandselDiscountList.length > 0){
					item.bindSkuHandselDiscountList.map((itemy:any) =>{
						itemx.ruleList.push({ itemId:itemy.skuId,itemNum:10})
					})
				}
				giftUseDiscountType.push(itemx)
			}
			itemData.giftUseDiscountType = giftUseDiscountType;
		}
		spuData.skuList.push(itemData)
	})
	const { method } = await spuCreate(spuData);
	if(method == 'success'){
		ElMessage.success('提交成功');
		router.go(-1)
	}
}

// 重置表单所有数据
const resetGoodsInfoData = () => {
	goodsInfoData.spuId = null;
	goodsInfoData.spuType = 6;
	goodsInfoData.salesChannel = [];
	goodsInfoData.brandId = null;
	goodsInfoData.spuName = ''; // 商品名称
	goodsInfoData.title = ''; // 商品标题
	goodsInfoData.subTitle = ''; // 商品副标题
	goodsInfoData.sortNumber = null; //商品排序
	goodsInfoData.spuTags = { //商品标签
		name:'',
		color:'#ff0000',
	};
	goodsInfoData.imgUrl = ''; // 商品主图1, 正方形
	goodsInfoData.imgOblongUrl = ''; // 商品主图2, 长方形
	goodsInfoData.imgScale = 0; // 商品副标题
	goodsInfoData.imgOnline = []; // 商品轮播图
	goodsInfoData.isVideo = false; // 是否有视频文件
	goodsInfoData.videoUrl = ''; // 是否有视频文件
	goodsInfoData.videoAutoplay = false; // 是否自动播放
	goodsInfoData.videoMuteplay = false; // 是否静音播放
	goodsInfoData.storeTypes = []; // 门店商品分类 分类id 联级选择器
	goodsInfoData.shopTypes = []; // 商城商品分类 分类id 联级选择器
	goodsInfoData.videoMuteplay = false; // 是否静音播放
	goodsInfoData.storeSalesType =  0; // 销售门店类型 0 全部 1部分
	goodsInfoData.storeSales = [] as Array<any>; // 销售门店ID {storeId:null,storeName:''}
	goodsInfoData.salesOnlineChannel= []; // 线上销售渠道
	goodsInfoData.transport= []; // 物流方式 1快递 2到店核销
	goodsInfoData.freightset = 1; // 运费设置，1固定邮费，2运费模板
	goodsInfoData.freightNum = null; // 运费固定邮费金额
	goodsInfoData.grounding = 0; //商品上架类型
	goodsInfoData.groundingTime = ''; // 上架时间
	goodsInfoData.delisting = 0; //商品下架类型
	goodsInfoData.delistingTime = ''; // 下架时间
	goodsInfoData.specList = [{ name: "默认", childItem: [ { id: null, name: "默认" } ]}]; //商品规格项数据
	goodsInfoData.multipleData.skuSpecList = goodsInfoData.specList[0].childItem; //商品规格项数据
	goodsInfoData.skuList = [goodsInfoData.multipleData]; // sku数据
	goodsInfoData.note = ''; // 商品详情
	goodsInfoData.browseAuthority = [1];  // 浏览权限 0 不参与 1 指定会员等级可见 2 指定付费会员等级可见 3指定标签组可见
	goodsInfoData.borwseMember = [] as Array<any>;  // 浏览权限会员
	goodsInfoData.borwsePaidMember = [] as Array<any>;  // 浏览权限付费会员
	goodsInfoData.borwseLaber = [] as Array<any>;  // 浏览权限标签组
	goodsInfoData.buyAuthority =  [1] as Array<number>;  // 购买权限 0 不参与 1 指定会员等级购买 2 指定付费会员等级购买 3指定标签组购买
	goodsInfoData.buyMember = [] as Array<any>;  // 购买权限会员
	goodsInfoData.buyPaidMember = [] as Array<any>;  // 购买权限付费会员
	goodsInfoData.buyLaber = [] as Array<any>; // 购买权限标签组
	goodsInfoData.quotaAuthority = 1; // 商品限购类型 0 不限购 1 统一限购 2 单一限购(根据sku限购)
	goodsInfoData.onceRestrictedPurchaseMinNum = null;  // 商品单次最少限购数量
	goodsInfoData.onceRestrictedPurchaseMaxNum = null;  // 商品单次最多限购数量
	goodsInfoData.onceRestrictedPurchaseNumber = 0;  // 商品单次限购数量
	goodsInfoData.longRestrictedPurchaseNumber = 0;  // 商品永久限购数量
	goodsInfoData.memberIntegral = 0; // 会员积分获取类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.paidmemberIntegral = 0; // 付费会员积分获取类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.memberIntegralDeduction = 0; // 会员积分抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.paidmemberIntegralDeduction = 0; // 付费会员积分抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.memberBalanceDeduction = 0; // 会员余额抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.paidmemberBalanceDeduction = 0; // 付费会员余额抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
	goodsInfoData.memberDiscount = 0; // 会员折扣类型 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)
	goodsInfoData.paidmemberDiscount = 0; // 付费会员折扣类型 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)
	goodsInfoData.commissionSet = 0; // 佣金设置类型 0 不参与 1 系统默认 2 单独设置佣金(根据sku限购)
}

onMounted(async () => {
	resetGoodsInfoData();
	// 商品类型是普通商品，不允许切换
	if (route.query.status == 'edit') {
		// 获取商品数据
		console.log(route.query.id)
		const { results } = await spuDetail(route.query.id);
		goodsInfoData.status = 'edit';
		goodsInfoData.isSingleSpec = results.isSingleSpec;
		goodsInfoData.tplId = results.tplId;
		goodsInfoData.spuId = results.spuId;
		goodsInfoData.spuType = results.spuType;  // 商品spu类型
		goodsInfoData.spuName = results.spuName;  // 商品spu类型	
		goodsInfoData.title = results.title;  
		goodsInfoData.subTitle = results.subtitle;
		goodsInfoData.sortNumber = results.sortNumber;
		goodsInfoData.spuTags.name = results.spuTags;
		goodsInfoData.spuTags.color = results.spuColor;
		// goodsInfoData.subTitle = results.subtitle;
		goodsInfoData.salesChannel = results.salesChannel;
		goodsInfoData.brandId = results.brandId;  
		goodsInfoData.imgUrl = results.imgUrl;
		goodsInfoData.imgOblongUrl = results.imgOblongUrl;
		goodsInfoData.imgScale = results.imgScale;
		goodsInfoData.imgOnline = results.imgOnline;
		goodsInfoData.isVideo = results.isVideo == 0 ? false : true;
		goodsInfoData.videoUrl = results.videoUrl;
		goodsInfoData.videoAutoplay = results.videoAutoplay == 0 ? false : true;
		goodsInfoData.videoMuteplay = results.videoMuteplay == 0 ? false : true;
		goodsInfoData.storeTypes = results.storeTypes;
		goodsInfoData.shopTypes = results.shopTypes;
		goodsInfoData.note = results.note;
		goodsInfoData.recommend = results.recommend;
		goodsInfoData.transport = results.transport;
		goodsInfoData.freightset = results.freightset;
		goodsInfoData.freightNum = results.freightset == 1? results.freight : null;
		goodsInfoData.freightId = results.freightset == 2? results.freight : null;	
		// 商品销售渠道线上
		goodsInfoData.salesOnlineChannel = results.salesOnlineChannel;
		goodsInfoData.priceType = results.priceType;
		goodsInfoData.priceValue = results.priceValue;
		goodsInfoData.grounding = results.productUp.selectId;
		goodsInfoData.groundingTime = results.productUp.ruleList[0].itemData;
		goodsInfoData.delisting = results.productDown.selectId;
		goodsInfoData.delistingTime = results.productDown.ruleList[0].itemData;


		goodsInfoData.specList = results.specList;
		goodsInfoData.skuList = [] as Array<any>;
		goodsInfoData.browseAuthority = results.browseAuthority.map((obj:any) => obj.selectId); // 浏览权限 0 不参与 1 指定会员等级可见 2 指定付费会员等级可见 3指定标签组可见
		goodsInfoData.buyAuthority = results.buyAuthority.map((obj:any) => obj.selectId); // 购买权限 0 不参与 1 指定会员等级购买 2 指定付费会员等级购买 3指定标签组购买
		goodsInfoData.quotaAuthority =  results.quotaAuthority.selectId; // 商品限购类型 1 不限购 2 统一限购 3 单一限购(根据sku限购)
		goodsInfoData.memberIntegral = results.memberIntegral.selectId; // 会员积分类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
		goodsInfoData.paidmemberIntegral =results.paidmemberIntegral.selectId;// 付费会员积分类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
		goodsInfoData.memberIntegralDeduction = results.deduMemberIntegral.selectId; // 会员积分抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
		goodsInfoData.paidmemberIntegralDeduction = results.deduPaidmemberIntegral.selectId; // 付费会员积分抵扣类型 0 不积分 1 全额积分 2 自定义积分(根据sku限购)
		goodsInfoData.memberBalanceDeduction = results.memberBalance.selectId;// 会员余额抵扣 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)
		goodsInfoData.paidmemberBalanceDeduction = results.paidmemberBalance.selectId; // 付费会员余额抵扣 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)
		goodsInfoData.memberDiscount = results.memberDiscount.selectId;// 会员折扣类型 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)
		goodsInfoData.paidmemberDiscount = results.paidmemberDiscount.selectId; // 付费会员折扣类型 0 不折扣 1 系统默认折扣 2 自定义折扣(根据sku限购)

		goodsInfoData.commissionSet = results.commissionSet.selectId; // 佣金设置类型 0 不参与 1 系统默认 2 单独设置佣金(根据sku限购)
		goodsInfoData.borwseMember = [] as Array<any>;
		if(goodsInfoData.browseAuthority.includes(2)){
			let qtData = results.browseAuthority.find((itemy:any) => itemy.selectId == 2);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.borwseMember.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		goodsInfoData.borwsePaidMember = [] as Array<any>;
		if(goodsInfoData.browseAuthority.includes(4)){
			let qtData = results.browseAuthority.find((itemy:any) => itemy.selectId == 4);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.borwsePaidMember.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		goodsInfoData.borwseLaber = [] as Array<any>;
		if(goodsInfoData.browseAuthority.includes(8)){
			let qtData = results.browseAuthority.find((itemy:any) => itemy.selectId == 8);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.borwseLaber.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		goodsInfoData.buyMember = [] as Array<any>;
		if(goodsInfoData.browseAuthority.includes(2)){
			let qtData = results.browseAuthority.find((itemy:any) => itemy.selectId == 2);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.buyMember.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		goodsInfoData.buyPaidMember = [] as Array<any>;
		if(goodsInfoData.buyAuthority.includes(4)){
			let qtData = results.buyAuthority.find((itemy:any) => itemy.selectId == 4);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.buyPaidMember.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		goodsInfoData.buyLaber = [] as Array<any>;
		if(goodsInfoData.buyAuthority.includes(8)){
			let qtData = results.buyAuthority.find((itemy:any) => itemy.selectId == 8);
			qtData.ruleList.map((itemx:any) =>{
				goodsInfoData.buyLaber.push({
					dictName: itemx.itemName,
					dictValue: itemx.itemId
				})
			})
		}
		results.skuList.map((item:any,index:number) =>{
			let xxItem = {
				skuSpecList: item.skuSpecList, // 规格组合
				salesStatus: 1, // 销售状态 0 下架 1 上架
				skuImgUrl:item.skuImgUrl,  // sku图片
				skuType: item.skuType, // 商品属性
				retailPrice:item.retailPrice, // 零售价
				referencePrice:item.referencePrice, // 划线价
				lowPrice:item.lowPrice, // 最低价
				costPrice:item.costPrice, // 成本价
				unit:item.unit, // 商品单位
				stock:item.stock, // 库存
				warnStock:item.warnStock, // 预警库存
				offlineSales:item.offlineSales, // 线下销量
				merchantCode:item.merchantCode, // 商家编码
				barCode:item.barCode, // 条形码
				giveGoods:item.giveGoods, // sku关联商品
				usableTimes:item.usableTimes, // 可用次数
				usableDuration:item.usableDuration, // 可用时长
				usableDurationUnit:item.usableDurationUnit, // 可用时长单位
				servicesDuration:item.servicesDuration, // 服务时长
				servicesFee: item.servicesFee, // 手工费
				isServices: item.isServices == 1 ? true : false, // 是否计算手工量
				isPerformance: item.isPerformance == 1 ? true : false, // 是否计算消耗业绩
				commission: item.commission, // 消耗提成
				commissionUnit: item.commissionUnit, // 消耗提成方式
				isDebtSales: item.isDebtSales == 1 ? true : false, // 是否欠款销售
				isDebtServices: item.isDebtServices == 1 ? true : false, // 是否欠款服务
				refundDeadline: item.refundDeadline, // 退款时限
				isAftersalesService: item.isAftersalesService == 1 ? true : false, // 是否支持售后
				cardValue: item.cardValue, // 储值卡金额(元)
				isGift: item.isGift == 1 ? true : false, // 是否存在赠金
				giftValue: item.giftValue, // 赠送金额
				giftAccountType:item.giftAccountType.selectId, // 赠送到账类型
				giftAccountValueList:item.giftAccountType.ruleList || [],
				cardPriceUseType: [], // 储值卡卡金额使用类型 默认0 *** (0 全部  1 商品类型 2 指定商品)
				cardPriceDiscountType: [], // 储值卡卡金额使用折扣类型 默认0 *** ( 0 不参与折扣  1 通用商品 2 商品类型 3 指定商品）
				cardBonusPriceUseType: [], // 储值卡卡赠送金额使用类型 默认0 *** (0 全部  1 商品类型 2 指定商品)
				cardBonusPriceDiscountType: [], // 储值卡卡赠送金额使用折扣类型 默认0 *** ( 0 不参与折扣  1 通用商品 2 商品类型 3 指定商品）
				bindTypeDiscountList:[],
				bindSkuDiscountList:[],
				bindTypeHandselUseList:[],
				bindSkuHandselUseList:[],
				restrictBuyData:{},
				memberIntegralData: {},
				paidMemberIntegralData: {},
				memberIntegralDeductionData: {},
				paidMemberIntegralDeductionData: {},
				memberDiscountData: {},
				paidMemberDiscountData: {},
				memberBalanceDeductionData: {},
				paidMemberBalanceDeductionData: {},
				commissionData:{},
				material: item.material, // 音视频商品关联文件
			}
			// 商品限购权限
			if(goodsInfoData.quotaAuthority == 2){
				goodsInfoData.onceRestrictedPurchaseMinNum = results.quotaAuthority.singleMinQuota;
				goodsInfoData.onceRestrictedPurchaseMaxNum = results.quotaAuthority.singleMaxQuota;
				goodsInfoData.longRestrictedPurchaseNumber = results.quotaAuthority.foreverQuota;
			}else if(goodsInfoData.quotaAuthority == 3){
				let qtData = results.quotaAuthority.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.restrictBuyData[`restrictBuyItem${itemz.shipLevel}`] = itemz.ruleValue;
				})
			}
			// 会员积分设置
			if(goodsInfoData.memberIntegral == 2){
				let qtData = results.memberIntegral.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.memberIntegralData[`memberIntegralItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.memberIntegralData[`memberIntegralItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 付费会员积分设置
			if(goodsInfoData.paidmemberIntegral == 2){
				let qtData = results.paidmemberIntegral.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.paidMemberIntegralData[`paidMemberIntegralItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.paidMemberIntegralData[`paidMemberIntegralItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 会员积分抵扣设置
			if(goodsInfoData.memberIntegralDeduction == 2){
				let qtData = results.deduMemberIntegral.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.memberIntegralDeductionData[`memberIntegralDeductionItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.memberIntegralDeductionData[`memberIntegralDeductionItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}

			// 付费会员积分抵扣设置
			if(goodsInfoData.paidmemberIntegralDeduction == 2){
				let qtData = results.deduPaidmemberIntegral.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.paidMemberIntegralDeductionData[`paidMemberIntegralDeductionItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.paidMemberIntegralDeductionData[`paidMemberIntegralDeductionItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}

			// 会员余额抵扣
			if(goodsInfoData.memberBalanceDeduction == 2){
				let qtData = results.memberBalance.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.memberBalanceDeductionData[`memberBalanceDeductionItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.memberBalanceDeductionData[`memberBalanceDeductionItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			
			// 付费会员余额抵扣设置
			if(goodsInfoData.paidmemberBalanceDeduction == 2){
				let qtData = results.paidmemberBalance.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.paidMemberBalanceDeductionData[`paidMemberBalanceDeductionItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.paidMemberBalanceDeductionData[`paidMemberBalanceDeductionItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 会员折扣设置
			if(goodsInfoData.memberDiscount == 2){
				let qtData = results.memberDiscount.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.memberDiscountData[`memberDiscountItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.memberDiscountData[`memberDiscountItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 付费会员折扣设置
			if(goodsInfoData.paidmemberDiscount == 2){
				let qtData = results.paidmemberDiscount.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.paidMemberDiscountData[`paidMemberDiscountItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.paidMemberDiscountData[`paidMemberDiscountItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 佣金设置
			if(goodsInfoData.commissionSet == 2){
				let qtData = results.commissionSet.ruleList.find((itemy:any) => itemy.skuId == item.skuId);
				qtData.memberList.map((itemz:any) =>{
					xxItem.commissionData[`commissionDataItem${itemz.shipLevel}`] = itemz.ruleValue;
					xxItem.commissionData[`commissionDataItem${itemz.shipLevel}Type`] = itemz.ruleType;
				})
			}
			// 使用类型
			if(item.useType.length > 0){
				item.useType.map((itemx:any) =>{
					xxItem.cardPriceUseType.push(itemx.selectId)
					if(itemx.selectId == 1){
						xxItem.bindTypeUseList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindTypeUseList.push({
								typeIdList:itemy.itemArray,
								name:itemy.itemName,
							})
						})
					}
					if(itemx.selectId == 2){
						xxItem.bindSkuUseList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindSkuUseList.push({
								skuId:itemy.skuId,
								spuName:itemy.itemName,
							})
						})
					}
				})
			}
			// 折扣类型
			if(item.useDiscountType.length > 0){
				item.useDiscountType.map((itemx:any) =>{
					xxItem.cardPriceDiscountType.push(itemx.selectId)
					if(itemx.selectId == 1){
						xxItem.bindTypeDiscountList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindTypeDiscountList.push({
								typeIdList:itemy.itemArray,
								name:itemy.itemName
							})
						})
					}
					if(itemx.selectId == 2){
						xxItem.bindSkuDiscountList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindSkuDiscountList.push({
								skuId:itemy.skuId,
								spuName:itemy.itemName,
							})
						})
					}
				})
			}
			// 赠金使用类型
			if(item.giftUseType.length > 0){
				item.giftUseType.map((itemx:any) =>{
					xxItem.cardBonusPriceUseType.push(itemx.selectId)
					if(itemx.selectId == 1){
						xxItem.bindTypeHandselUseList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindTypeHandselUseList.push({
								typeIdList:itemy.itemArray,
								name:itemy.itemName,
							})
						})
					}
					if(itemx.selectId == 2){
						xxItem.bindSkuHandselUseList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindSkuHandselUseList.push({
								skuId:itemy.skuId,
								spuName:itemy.itemName,
							})
						})
					}
				})
			}
			// 赠金折扣类型
			if(item.useType.length > 0){
				item.useType.map((itemx:any) =>{
					xxItem.cardBonusPriceDiscountType.push(itemx.selectId)
					if(itemx.selectId == 1){
						xxItem.bindTypeHandselDiscountList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindTypeHandselDiscountList.push({
								typeIdList:itemy.itemArray,
								name:itemy.itemName,
							})
						})
					}
					if(itemx.selectId == 2){
						xxItem.bindSkuHandselDiscountList = []
						itemx.ruleList.map((itemy:any) =>{
							xxItem.bindSkuHandselDiscountList.push({
								skuId:itemy.skuId,
								spuName:itemy.itemName,
							})
						})
					}
				})
			}
			goodsInfoData.skuList.push(xxItem)
		});
	}else{
		// 新增时设置默认规格
		goodsInfoData.status = 'add';
	}
	getConfigDataFun();
});

</script>
<style scoped lang="scss">
:deep(.el-card__body){
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table{
		flex: 1;
		.el-table__inner-wrapper::before{
			background: none !important;
		}
	}
	.el-tabs__content{
		display: flex;
		flex-direction: column;
		flex: 1;
		height: inherit;
		.el-tab-pane{
			display: flex;
			flex-direction: column;
			flex: 1;
			height: inherit;
		}
	}
}
</style>
